import Pinyin from 'js-pinyin';
Pinyin.setOptions({
	charCase: 0
});
//获取首字母列表
export function getFirstList(arr, key) {
	arr = arr.sort((pre, next) => {
		return Pinyin.getFullChars(pre[key]).localeCompare(Pinyin.getFullChars(next[key]))
	})
	let list = []
	if (Array.isArray(arr)) {
		arr.map(item => {
			let first = Pinyin.getFullChars(item[key])
			let flag = list.findIndex(res => {
				return res.key == first[0]
			})
			if (flag == -1) {
				list.push({
					key: first[0],
					list: [item]
				})
			} else {
				list[flag].list.push(item)
			}
		})
		return list
	}
}